package com.adrainty.spring.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileUtil {

    private FileUtil() {}

    public static List<File> getAllClassFile(File file) {
        if (!file.isDirectory()) throw new RuntimeException("Path is not a directory !");
        List<File> files = new ArrayList<>();
        getAllClassFile(file, files);
        return files;
    }

    private static void getAllClassFile(File file, List<File> files) {
        assert file != null;
        if (file.isDirectory()) {
            File[] subFiles = file.listFiles();
            assert subFiles != null;
            for (File subFile : subFiles) {
                if (subFile.isDirectory()) {
                    getAllClassFile(subFile, files);
                } else {
                    files.add(subFile);
                }
            }
        } else {
            files.add(file);
        }
    }


}
